import { useRef } from "react";

function Myinput(props) {
  const { isShow,addItem } = props;
  const inputref=useRef();
const submit=()=> {
   
    const inputvalue=inputref.current.value.trim();
   
    if (inputvalue.length == 0) {
      alert("请输入内容");
      return;
    }
    addItem(inputvalue);
    inputref.current.value=''
  }
  return (
    <>
      {isShow ? (
        <div>
          <input type="text" ref={inputref} placeholder="请输入" />
          <button type="button"  onClick={submit}>Submit</button>
        </div>
      ) : (
        ""
      )}
    </>
  );
}
export default Myinput;
